$(function() {
	console.log("{$item.qty}")
	var qty="{$item.qty}"-0
	var online="{$item.online}"-0
	var driverstatistics = echarts.init(document.getElementById('driverstatistics'));
	var noonline=qty-online
	option = {
		tooltip: {
			trigger: 'item',
			formatter: "{a} <br/>{b}: {c} ({d}%)"
		},
		legend: {
			orient: 'vertical',
			x: 'left',
			data: ['在线司机', '不在线司机', '单位订单数']
		},
		series: [{
			name: '订单数量',
			type: 'pie',
			radius: ['50%', '70%'],
			avoidLabelOverlap: false,
			label: {
				normal: {
					show: false,
					position: 'center'
				},
				emphasis: {
					show: true,
					textStyle: {
						fontSize: '20',
						fontWeight: 'bold'
					}
				}
			},
			labelLine: {
				normal: {
					show: false
				}
			},
			data: [{
					value: {$item.online?:0},
					name: '在线司机'
				},
				{
					value: {$item.online?($item.qty-$item.online):0},
					name: '不在线司机'
				}
			]
		}]
	};
	driverstatistics.setOption(option);
	
	$('.driverstat').on('change', function() {
		console.log($(this).val())
		if($(this).val()==1){
			$('.driver-name').attr('name','name')
			$('.driver_id').attr('name','driver_id')
			$('.company').attr('name','')
			$('.car_rental_id').attr('name','')
		}else if($(this).val()==2){
			$('.driver-name').attr('name','')
			$('.driver_id').attr('name','')
			$('.company').attr('name','car_rental_name')
			$('.car_rental_id').attr('name','car_rental_id')
		}
		if($(this).val() == 1) {
			$('.driver-name').attr('type', 'text')
			$('.company').attr('type', 'hidden')

		} else {
			$('.driver-name').attr('type', 'hidden')
			$('.company').attr('type', 'text')
		} 
	})
	$('.timeclassify>button').on('click', function() {
		$('.time').val($(this).data('val'))	
	});
	$('.driver-name').on('click', function() {
		choosecar("{:url('index',['op'=>'search'])}")
	});
	$('.company').on('click', function() {
		choosecar("{:url('company/index',['op'=>'search'])}")
	});
	$('.online-time').on('click',function(){
		layer.open({
		  type: 1,
		  title:'在线时长',
		  skin: 'layui-layer-rim', //加上边框
		  area: ['420px', '240px'], //宽高
		  content: `
		  <div class='am-u-sm-12'>
		  	<table width="100%" class="am-table am-table-compact am-table-bordered am-table-radius am-table-striped tpl-table-black am-text-nowrap">
		  		<thead>
		  			<tr>
		  				<th>司机姓名</th>
		  				<th>上线时间</th>
		  				<th>下线时间</th>
		  			</tr>
		  		</thead>
		  		<tbody>
		  			{foreach $list as $key => $item}
		  			<tr>
		  				<td>{$item.name}</td>
		  				<td>{$item.onlinetime}</td>
		  				<td>{$item.xiaxian}</td>
		  			</tr>
		  			{/foreach}
		  		</tbody>
		  	</table>
		  </div>`
		});
	})
})